package com.mvc.Web;

import com.mvc.Pojo.Mvcdemo;
import com.mvc.Service.ImPI.UserServiceImpI;
import com.mvc.Service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @auther linke
 * @create 2021-10-21 17:47
 * Web层，用于页面访问
 */
@WebServlet("/mvcServlet")
public class MvcServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserService userService = new UserServiceImpI();
        List<Mvcdemo> mvcdemos = userService.findByAll();
        req.setAttribute("mvcdemos", mvcdemos);
        System.out.println(mvcdemos);

        //页面请求转发
        req.getRequestDispatcher("/JspMvc.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
